package com.moneywelcome.investassembly.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.moneywelcome.investfacade.InvestDiscussApi;
import com.moneywelcome.orderfacade.dto.CommentDto;
import com.moneywelcome.orderfacade.dto.ReplyDto;
import com.moneywelcome.investfacade.vo.CommentPageVo;
import com.moneywelcome.orderfacade.vo.CommentVo;
import com.moneywelcome.orderfacade.vo.ReplyVo;
import com.moneywelcome.orderfacade.DiscussApi;
import com.moneywelcome.orderfacade.vo.OrderPageVo;
import com.moneywelcome.results.PageResult;
import com.moneywelcome.results.Result;
import com.moneywelcome.validate.ValidationUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Slf4j
@Api(tags = "用户讨论区服务")
public class InvestDiscussApiImpl implements InvestDiscussApi {
    @Autowired
    private DiscussApi discussApi;

    @ApiOperation("根据产品加载评论")
    @Override
    public Result<PageResult<CommentDto>> loadComment(String goldId) {
        ValidationUtils.validate(goldId);
        PageResult<com.moneywelcome.orderfacade.dto.CommentDto> data = discussApi.loadComment(goldId).getData();
        PageResult pageResult = BeanUtil.copyProperties(data, PageResult.class);
        pageResult.setData(BeanUtil.copyToList(data.getData(),CommentDto.class));
        return Result.success(data);
    }
    @ApiOperation("发表评论")
    @Override
    public Result<CommentDto> makeComment(CommentVo commentVo) {
        ValidationUtils.validate(commentVo);
        return discussApi.comment(commentVo);
    }
    @ApiOperation("发表回复")
    @Override
    public Result<ReplyDto> makeReply(ReplyVo replyVo) {
        ValidationUtils.validate(replyVo);
        return discussApi.reply(replyVo);
    }
}
